﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CUREDataAccessLayers.Public
{
    /// 根据当前时间获取当前班次
    /// <summary>
    /// 根据当前时间获取当前班次
    /// </summary>
    public static class ShiftNow
    {
        /// 根据当前时间获取当前班次
        /// <summary>
        /// 根据当前时间获取当前班次
        /// </summary>
        /// <returns>当前班次</returns>
        public static string GetShiftNow()
        {
            DateTime date = DateTime.Now;//当前时间
            string shift = string.Empty;//班次
            string datenow = DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo);//当前时间yyyy-MM-dd
            string dateshift = DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);//当前时间yyyyMMdd

            if (date >= DateTime.Parse("" + datenow + " 07:30:00") && date < DateTime.Parse("" + datenow + " 15:30:00"))
            {
                return dateshift + "1";//早
            }
            if (date >= DateTime.Parse("" + datenow + " 15:30:00") && date < DateTime.Parse("" + datenow + " 23:30:00"))
            {
                return dateshift + "2";//中
            }
            if (date >= DateTime.Parse("" + datenow + " 23:30:00") && date <= DateTime.Parse("" + datenow + " 23:59:59"))
            {
                return dateshift + "3";//晚
            }
            if (date >= DateTime.Parse("" + datenow + " 00:00:00") && date < DateTime.Parse("" + datenow + " 07:30:00"))
            {
                dateshift = DateTime.Now.AddDays(-1).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                return dateshift + "3";//晚
            }
            return shift;
        }
    }

    /// <summary>
    /// 根据时间获取班次
    /// </summary>
    public static class GetShift
    {
        /// 获取当前班次
        /// <summary>
        /// 获取当前班次
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string GetNowShift(DateTime dt)
        {
            string nowshift = string.Empty;
            int nowdatehms = int.Parse(dt.ToString("HHmmss"));
            if (nowdatehms >= 0 && nowdatehms < 73000)
            {
                nowshift = dt.AddDays(-1).ToString("yyyyMMdd") + "3";
            }
            else if (nowdatehms >= 73000 && nowdatehms < 153000)
            {
                nowshift = dt.ToString("yyyyMMdd") + "1";
            }
            else if (nowdatehms >= 153000 && nowdatehms < 233000)
            {
                nowshift = dt.ToString("yyyyMMdd") + "2";
            }
            else if (nowdatehms >= 233000 && nowdatehms <= 240000)
            {
                nowshift = dt.ToString("yyyyMMdd") + "3";
            }
            return nowshift;
        }

        /// 获取上一班次
        /// <summary>
        /// 获取上一班次
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string GetLastShift(DateTime dt)
        {
            string lastshift = string.Empty;
            int nowdatehms = int.Parse(dt.ToString("HHmmss"));
            if (nowdatehms >= 0 && nowdatehms < 73000)
            {
                lastshift = dt.AddDays(-1).ToString("yyyyMMdd") + "2";
            }
            else if (nowdatehms >= 73000 && nowdatehms < 153000)
            {
                lastshift = dt.AddDays(-1).ToString("yyyyMMdd") + "3";
            }
            else if (nowdatehms >= 153000 && nowdatehms < 233000)
            {
                lastshift = dt.ToString("yyyyMMdd") + "1";
            }
            else if (nowdatehms >= 233000 && nowdatehms <= 240000)
            {
                lastshift = dt.ToString("yyyyMMdd") + "2";
            }
            return lastshift;
        }

        /// 获取下一班次
        /// <summary>
        /// 获取下一班次
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string GetNextShift(DateTime dt)
        {
            string nextshift = string.Empty;
            int nowdatehms = int.Parse(dt.ToString("HHmmss"));
            if (nowdatehms >= 0 && nowdatehms < 73000)
            {
                nextshift = dt.ToString("yyyyMMdd") + "1";
            }
            else if (nowdatehms >= 73000 && nowdatehms < 153000)
            {
                nextshift = dt.ToString("yyyyMMdd") + "2";
            }
            else if (nowdatehms >= 153000 && nowdatehms < 233000)
            {
                nextshift = dt.ToString("yyyyMMdd") + "3";
            }
            else if (nowdatehms >= 233000 && nowdatehms <= 240000)
            {
                nextshift = dt.AddDays(+1).ToString("yyyyMMdd") + "1";
            }
            return nextshift;
        }
    }
}
